<?php
session_start();
include 'objects/User.inc';

if (isset($_SESSION['user'])) {
    $user = unserialize($_SESSION['user']);
} else {
    $user = new User();
}
if (!$user->isLogged()) {
    header("Location: index.php");
    exit();
}
?><!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Modificar usuario</title>
        <link rel="stylesheet" type="text/css" href="css/basic.css" />
        <script type="text/javascript" src="script/main.js"></script>
        <style type="text/css">
            body {
                background-color: #CCC;
                text-align: center;
            }
            table#form {	text-align: center;
                         color: #000;
            }
        </style>
    </head>

    <body>
        <img alt="logo2" src="img/boulevard.jpg" style="margin-top: 3em;"/>
        <br>
        <table width="577" cellspacing="1" cellpadding="3" border="0" align='center'>
            <tr>
                <td width="569" bgcolor="#CA0000"><b><font color="#FFFFFF" size="3" face="verdana, arial, helvetica">MODIFICAR USUARIOS</font></b></td>

            <tr>
                <td height="238" bgcolor="#F5ECB9">
                    <h2>&nbsp;</h2>
                    <p id="msg"></p><input type="hidden" id="tmp"><br>
                    <table id="list">
                        <thead>
                            <tr>
                                <th>Nombre</th>
                                <th>Permiso</th>
                                <th>Ingresos</th>
                                <th>Clientes</th>
                                <th>Usuarios</th>
                                <th></th>
                                <th></th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <td colspan="7"></td>
                            </tr>
                        </tfoot>
                        <tbody>
                            <?php
                            $ins = new User();
                            if ($objs = $ins->getAllBy()) {
                                foreach ($objs as $obj) {
                                    $href = "href=\"form_usuario.php?id=" . $obj->encodeId() . "\"";
                                    $onclick = "onclick=\"delItem('" . $obj->encodeId() . "','usuario',this)\"";
                                    $ing = ($obj->getPermiso()->ingreso === '1'? "checked='checked'":"");
                                    $cli = ($obj->getPermiso()->clientes === '1'? "checked='checked'":"");
                                    $usu = ($obj->getPermiso()->usuarios === '1'? "checked='checked'":"");
                                    ?>
                                    <tr>
                                        <td><?php echo $obj->nombre; ?></td>
                                        <td><?php echo $obj->getPermiso()->permiso; ?></td>
                                        <td><input type="checkbox" name="check" <?php echo $ing; ?>/></td>
                                        <td><input type="checkbox" name="check" <?php echo $cli; ?>/></td>
                                        <td><input type="checkbox" name="check" <?php echo $usu; ?>/></td>
                                        <td><a <?php echo $href; ?> ><img src="img/edit.png" alt="details" title="Details"></a></td>
                                        <td><img src="img/eliminar.png" alt="delete" title="Delete" <?php echo $onclick; ?> ></td>
                                    </tr>
                                    <?php
                                }
                            } else {
                                echo $ins->msg;
                            }
                            ?>
                        </tbody>
                    </table>
                    <input type="button" name="cancelar" id="volver" value="Volver" onclick="window.location = 'menu.php';" style="margin: 3em;"/>
                </td>
            </tr>
        </table>
        <br>
        <br>
        <br>
        <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0; border-color: #111111; height: 53px" width="100%" id="AutoNumber3">
            <tr>
                <td width="100%" height="26" style="border-style: none; border-width: medium" bgcolor="#CA0000">
                    <p align="center"><b><font face="Arial" size="1" color="#000000">Proyectos Informaticos II /2013</font></b>
                </td>
            </tr>
        </table>
    </body>
</html>